/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.FileNotFoundException;
import java.io.IOException;
import lucava.importer.java.XmlImporter;
import lucava.importer.uspeed.FileImporter;
import lucava.metamodel.dot.DotGraph;
import lucava.metamodel.dot.visitor.DotFileGenerator;
import lucava.metamodel.java.MetaModel;
import lucava.metamodel.java.visitor.DotMetaModelGenerator;
import lucava.metamodel.uspeed.UspeedDocument;
import lucava.metamodel.uspeed.visitor.XmlVisitor;
import lucava.util.GraphVizGenerator;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

/**
 *
 * @author glenn
 */
public class UspeedToJavaTester {

    public static void main(String[] args) throws FileNotFoundException, IOException, JDOMException {
        FileImporter parser = new FileImporter();
        UspeedDocument document = parser.load("data/example2.uspeed");

        XmlVisitor visitor = new XmlVisitor();
        document.accept(visitor);

        Document xmlDoc = visitor.buildDocument();
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());


        XmlImporter importer = new XmlImporter();
        MetaModel model = importer.loadContent(outputter.outputString(xmlDoc));

        DotMetaModelGenerator dotGen = new DotMetaModelGenerator();
        model.accept(dotGen);

        DotGraph graph = dotGen.getGeneratedGraph();
        DotFileGenerator generator = new DotFileGenerator();
        graph.accept(generator);

        GraphVizGenerator.generatePNGFromString(generator.getGeneratedFile().getContent(), "data/test/GeneratedGraph4.png");
    }
}
